package jjwt.study.Service;

import jjwt.study.Pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * 描述:
 *
 * @author Ychiha
 * @version 1.0
 * @date 14/1/2022 下午5:33
 */
@Service
public class UserService implements UserDetailsService {

    //测试用的账号(实际项目用数据库验证验证处理)
    private final String matchUsername = "ychiha";
    //测试用的密码(实际项目用数据库数据验证处理)
    private final String matchPassword = "123456";

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        System.out.println("执行JWT包内方法");
        System.out.println(username);

        String password = passwordEncoder.encode(matchPassword);
        return new User(matchUsername,password, AuthorityUtils.commaSeparatedStringToAuthorityList("yzm"));
    }
}
